package com.CampaignManager.client;

import com.CampaignManager.shared.UnitTypeDTO;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class AddUnitTypeForm extends Composite {

	private static AddUnitTypeFormUiBinder uiBinder = GWT.create(AddUnitTypeFormUiBinder.class);
	interface AddUnitTypeFormUiBinder extends UiBinder<Widget, AddUnitTypeForm> {
	}

	private CampaignManager mainForm = null;
	
	public AddUnitTypeForm(CampaignManager mainForm) {
		this.mainForm = mainForm;
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiField
	TextBox nameTextBox;
	@UiField
	TextBox factionTextBox;
	@UiField
	TextBox allowanceTextBox;
	@UiField
	TextBox minPointsTextBox;
	@UiField
	TextBox maxPointsTextBox;
	@UiField
	TextBox href;
	@UiField
	TextBox attachedTextBox;
	
	@UiField
	Button Save;
	@UiField
	Button Cancel;
	
	@UiHandler("Save")
	void saveClick(ClickEvent event) {
		UnitTypeDTO unitType = new UnitTypeDTO();
		unitType.setName(nameTextBox.getText());
		unitType.setFieldAllowance(Long.parseLong(allowanceTextBox.getText()));
		unitType.setMinPoints(Long.parseLong(minPointsTextBox.getText()));
		unitType.setMaxPoints(Long.parseLong(maxPointsTextBox.getText()));
		unitType.setHref(href.getText());
		unitType.setAttached(attachedTextBox.getText());
		this.mainForm.SaveNewUnitType(unitType);
	}
}
